package com.qf.dao;

import com.qf.bean.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

/**
 * 2019/12/4
 * Administrator
 * springboot1204
 * 面向对象面向君  不负代码不负卿
 */
@Repository
public class StudentDao2Impl implements  StudentDao2 {
    @Autowired
    private JdbcTemplate jdbcTemplate;

    @Override
    public List<Student> findall() {
        List<Student> students = jdbcTemplate.query("select * from student", new RowMapper<Student>() {
            @Override
            public Student mapRow(ResultSet resultSet, int i) throws SQLException {
                Student student = new Student();
                student.setSname2(resultSet.getString("sname2"));
                student.setSex(resultSet.getString("sex"));
                return student;
            }
        });
        return students;
    }
}
